home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / TouchMe 1.1.1.sit / touchMe 1.11 Folder / CW9 PP source / source / Common / CDateEditField.cp next >
Text File  |  1996-08-08  |  8KB  |  371 lines

  1. // ==================================================
  2. //    CDateEditField.cp
  3. //    Copyright (C) 1996 Mizutori Tetsuya, July 4 1996.
  4. // ==================================================
  5. //    All documents are pretty-printed in Geneva 10-point font.
  6.  
  7. #include <LDialogBox.h>
  8. #include <UDrawingState.h>
  9.  
  10. #include "touchMeConstants.h"
  11. #include "CDateEditField.h"
  12. #include "UDateTime.h"
  13.  
  14.  
  15. // --------------------------------------------------
  16. //        ・ CreateDateEditFieldStream [static]
  17. // --------------------------------------------------
  18.  
  19. CDateEditField *
  20. CDateEditField::CreateDateEditFieldStream(
  21.     LStream    *inStream )
  22. {
  23.     return new CDateEditField( inStream );
  24. }
  25.  
  26.  
  27. // --------------------------------------------------
  28. //        ・ CDateEditField
  29. // --------------------------------------------------
  30.  
  31. CDateEditField::CDateEditField()
  32. {
  33.     mHasChanged = false;
  34. }
  35.  
  36.  
  37. // --------------------------------------------------
  38. //        ・ CDateEditField(const CDateEditField&)
  39. // --------------------------------------------------
  40.  
  41. CDateEditField::CDateEditField(
  42.     const CDateEditField    &inOriginal )
  43.         : LEditField( inOriginal ),  LListener( inOriginal ), LBroadcaster( inOriginal )
  44. {
  45.     mHasChanged = false;
  46. }
  47.  
  48.  
  49. // --------------------------------------------------
  50. //        ・ CDateEditField(SPaneInfo&, ... , inHasWordWrap, ...)
  51. // --------------------------------------------------
  52.  
  53. CDateEditField::CDateEditField(
  54.     const SPaneInfo        &inPaneInfo,
  55.     Str255            inString,
  56.     ResIDT            inTextTraitsID,
  57.     Int16            inMaxChars,
  58.     Boolean            inHasBox,
  59.     Boolean            inHasWordWrap,
  60.     KeyFilterFunc        inKeyFilter,
  61.     LCommander        *inSuper)
  62.         : LEditField( inPaneInfo, inString, inTextTraitsID, inMaxChars,
  63.                 inHasBox, inHasWordWrap, inKeyFilter, inSuper)
  64. {
  65.     mHasChanged = false;
  66. }
  67.  
  68.  
  69. // --------------------------------------------------
  70. //        ・ CDateEditField(SPaneInfo&, ... , inAttributes, ...)
  71. // --------------------------------------------------
  72.  
  73. CDateEditField::CDateEditField(
  74.     const SPaneInfo        &inPaneInfo,
  75.     Str255            inString,
  76.     ResIDT            inTextTraitsID,
  77.     Int16            inMaxChars,
  78.     Uint8            inAttributes,
  79.     KeyFilterFunc        inKeyFilter,
  80.     LCommander        *inSuper)
  81.         : LEditField( inPaneInfo, inString, inTextTraitsID, inMaxChars,
  82.                 inAttributes, inKeyFilter, inSuper)
  83. {
  84.     mHasChanged = false;
  85. }
  86.  
  87.  
  88. // --------------------------------------------------
  89. //        ・ CDateEditField(LStream*)
  90. // --------------------------------------------------
  91.  
  92. CDateEditField::CDateEditField(
  93.     LStream    *inStream )
  94.         : LEditField( inStream )
  95. {
  96.     mHasChanged = false;
  97. }
  98.  
  99.  
  100. // --------------------------------------------------
  101. //        ・ ~CDateEditField
  102. // --------------------------------------------------
  103.  
  104. CDateEditField::~CDateEditField()
  105. {
  106. }
  107.  
  108.  
  109. // --------------------------------------------------
  110. //        ・ ListenToMessage
  111. // --------------------------------------------------
  112. void
  113. CDateEditField::ListenToMessage(
  114.     MessageT    inMessage,
  115.     void        *ioParam )
  116. {
  117. #pragma unused( inMessage, ioParam )
  118.  
  119.     //PaneIDT    thisPaneID = GetPaneID();
  120.     //Int32    thisUserCon = GetUserCon();
  121.  
  122.     // Do not refresh the EditField if click is still in this EditField.
  123.     //if ( inMessage == thisUserCon ) return;
  124.  
  125.     //RefreshEditField();
  126. }
  127.  
  128.  
  129. // --------------------------------------------------
  130. //        ・ UserChangedText
  131. // --------------------------------------------------
  132.  
  133. void
  134. CDateEditField::UserChangedText( void )
  135. {
  136.     LEditField::UserChangedText();
  137.  
  138.     mHasChanged = true;
  139. }
  140.  
  141.  
  142. // --------------------------------------------------
  143. //        ・ ClickSelf
  144. // --------------------------------------------------
  145.  
  146. void
  147. CDateEditField::ClickSelf(
  148.     const SMouseDownEvent &    inMouseDown )
  149. {
  150.     LEditField::ClickSelf( inMouseDown );
  151.  
  152. //    Int32    thisUserCon = GetUserCon();
  153. //    BroadcastMessage( (MessageT) thisUserCon, nil );
  154. }
  155.  
  156.  
  157. // --------------------------------------------------
  158. //        ・ BeTarget
  159. // --------------------------------------------------
  160.  
  161. void
  162. CDateEditField::BeTarget( void )
  163. {
  164.     LEditField::BeTarget();
  165.  
  166. //    Int32    thisUserCon = GetUserCon();
  167. //    BroadcastMessage( (MessageT) thisUserCon, nil );
  168. }
  169.  
  170.  
  171. // --------------------------------------------------
  172. //        ・ DontBeTarget
  173. // --------------------------------------------------
  174.  
  175. void
  176. CDateEditField::DontBeTarget( void )
  177. {
  178.     LEditField::DontBeTarget();
  179.  
  180. //    Int32    thisUserCon = GetUserCon();
  181. //    BroadcastMessage( (MessageT) thisUserCon, nil );
  182.  
  183.     long        theSelStart, theSelEnd;
  184.     GetSelect( theSelStart, theSelEnd );
  185.     RefreshEditField();
  186.     SetSelect( theSelStart, theSelEnd );
  187. }
  188.  
  189.  
  190. // ==================================================
  191. //    Common functions
  192. // ==================================================
  193.  
  194. // --------------------------------------------------
  195. //        ・ GetTEActive
  196. // --------------------------------------------------
  197.  
  198. Boolean
  199. CDateEditField::GetTEActive( void )
  200. {
  201.     TEHandle    theTextEditH = GetMacTEH();
  202.  
  203.     return  (Boolean) ( (**theTextEditH).active != 0 );
  204. }
  205.  
  206.  
  207. // --------------------------------------------------
  208. //        ・ SetTEActive
  209. // --------------------------------------------------
  210.  
  211. void
  212. CDateEditField::SetTEActive(
  213.     const Boolean    inStatus )
  214. {
  215.     TEHandle    theTextEditH = GetMacTEH();
  216.  
  217.     if ( inStatus )  ::TEActivate( theTextEditH );
  218.     else  ::TEDeactivate( theTextEditH );
  219.  
  220.     ::TEIdle( theTextEditH );
  221. }
  222.  
  223.  
  224. // --------------------------------------------------
  225. //        ・ GetSelect
  226. // --------------------------------------------------
  227.  
  228. void
  229. CDateEditField::GetSelect(
  230.      long &        outSelStart,
  231.      long &        outSelEnd )
  232. {
  233.     TEHandle    theTextEditH = GetMacTEH();
  234.  
  235.     outSelStart = (**theTextEditH).selStart;
  236.     outSelEnd = (**theTextEditH).selEnd;
  237. }
  238.  
  239.  
  240. // --------------------------------------------------
  241. //        ・ SetSelect
  242. // --------------------------------------------------
  243.  
  244. void
  245. CDateEditField::SetSelect(
  246.     const long        inSelStart,
  247.     const long        inSelEnd )
  248. {
  249.     TEHandle    theTextEditH = GetMacTEH();
  250.     ::TESetSelect( inSelStart, inSelEnd, theTextEditH );
  251. }
  252.  
  253.  
  254. // --------------------------------------------------
  255. //        ・ GetText
  256. // --------------------------------------------------
  257.  
  258. void
  259. CDateEditField::GetText(
  260.     Str255        outString )
  261. {
  262.     TEHandle    theHandle = GetMacTEH();
  263.  
  264.     outString[0] = (**theHandle).teLength;
  265.     ::BlockMoveData( *((**theHandle).hText), &outString[1], outString[0] );
  266. }
  267.  
  268. // --------------------------------------------------
  269. //        ・ SetText
  270. // --------------------------------------------------
  271.  
  272. void
  273. CDateEditField::SetText(
  274.     const Str255    inString )
  275. {
  276.     TEHandle    theHandle = GetMacTEH();
  277.  
  278.     ::TESetText( &inString[1], inString[0], theHandle );
  279.  
  280.     Refresh();
  281.  
  282.     mHasChanged = true;
  283. }
  284.  
  285.  
  286. // --------------------------------------------------
  287. //        ・ SetTextAndRefresh
  288. // --------------------------------------------------
  289.  
  290. void
  291. CDateEditField::SetTextAndRefresh(
  292.     const Str255    inString )
  293. {
  294.     SetText( inString );
  295.     RefreshEditField();
  296. }
  297.  
  298.  
  299. // --------------------------------------------------
  300. //        ・ SetDateTime
  301. // --------------------------------------------------
  302.  
  303. void
  304. CDateEditField::SetDateTime(
  305.     const unsigned long    inDateTimeSeconds )
  306. {
  307.     PaneIDT    thisPaneID = GetPaneID();
  308.     Str255    theDateString, theTimeString;
  309.  
  310.     UDateTime::SecondsToDateTimeString( inDateTimeSeconds, theDateString, theTimeString );
  311.  
  312.     switch ( thisPaneID ) {
  313.         case kTmeD_CrTextEditDate:
  314.         case kTmeD_MdTextEditDate:
  315.             SetText( theDateString );
  316.             break;
  317.  
  318.         case kTmeD_CrTextEditTime:
  319.         case kTmeD_MdTextEditTime:
  320.             SetText( theTimeString );
  321.             break;
  322.     }
  323.  
  324.     // Do not need refresh this EditField.
  325.     mHasChanged = false;
  326. }
  327.  
  328.  
  329. // --------------------------------------------------
  330. //        ・ RefreshEditField
  331. // --------------------------------------------------
  332.  
  333. void
  334. CDateEditField::RefreshEditField( void )
  335. {
  336.     PaneIDT    thisPaneID = GetPaneID();
  337.  
  338.     // Do not refresh the EditField if text has not been changed.
  339.     if ( ! mHasChanged ) return;
  340.  
  341.     // Refresh the EditField, and then reset the flag 'mHasChanged'.
  342.     Str63    theStrDate="¥p1", theStrTime="¥p0";
  343.     unsigned long    theSeconds;
  344.  
  345.     switch ( thisPaneID ) {
  346.         case kTmeD_CrTextEditDate:
  347.         case kTmeD_MdTextEditDate:
  348.         {
  349.             GetText( theStrDate );
  350.             UDateTime::DateTimeStringToSeconds(theStrDate,theStrTime,theSeconds);
  351.             UDateTime::SecondsToDateTimeString(theSeconds,theStrDate,theStrTime);
  352.             SetText( theStrDate );
  353.         }
  354.         break;
  355.  
  356.         case kTmeD_CrTextEditTime:
  357.         case kTmeD_MdTextEditTime:
  358.         {
  359.             GetText( theStrTime );
  360.             UDateTime::DateTimeStringToSeconds(theStrDate,theStrTime,theSeconds);
  361.             UDateTime::SecondsToDateTimeString(theSeconds,theStrDate,theStrTime);
  362.             SetText( theStrTime );
  363.         }
  364.         break;
  365.     }
  366.  
  367.     mHasChanged = false;
  368. }
  369.  
  370. // end of program
  371.